package com.qxbb.report.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.qxbb.report.Enum.DescribeType;
import com.qxbb.report.bo.ProductHistoryBO;
import com.qxbb.report.dao.ChainInOutStockMapper;
import com.qxbb.report.pojo.ChainInOutStock;
import com.qxbb.report.service.IChainInOutStockService;
import com.qxbb.report.utils.StringUtils;
import com.qxbb.report.vo.ProductHistoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-15
 */
@Service
public class ChainInOutStockServiceImpl implements IChainInOutStockService {
    @Autowired
    private ChainInOutStockMapper chainInOutStockMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param clientId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public ChainInOutStock selectChainInOutStockByClientId(Long clientId) {
        return chainInOutStockMapper.selectChainInOutStockByClientId(clientId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param chainInOutStock 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<ChainInOutStock> selectChainInOutStockList(ChainInOutStock chainInOutStock) {
        return chainInOutStockMapper.selectChainInOutStockList(chainInOutStock);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param chainInOutStock 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertChainInOutStock(ChainInOutStock chainInOutStock) {
        return chainInOutStockMapper.insertChainInOutStock(chainInOutStock);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param chainInOutStock 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateChainInOutStock(ChainInOutStock chainInOutStock) {
        return chainInOutStockMapper.updateChainInOutStock(chainInOutStock);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param clientIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteChainInOutStockByClientIds(Long[] clientIds) {
        return chainInOutStockMapper.deleteChainInOutStockByClientIds(clientIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param clientId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteChainInOutStockByClientId(Long clientId) {
        return chainInOutStockMapper.deleteChainInOutStockByClientId(clientId);
    }


    @Override
    public List<ProductHistoryVO> selectProductHistory(ProductHistoryBO productHistoryBO) {
        List<ProductHistoryVO> list = new ArrayList<>();
        list = chainInOutStockMapper.selectProductHistory(productHistoryBO);
        for (ProductHistoryVO productHistoryVO : list) {
            char[] chars = productHistoryVO.getCode().toCharArray();
            int index = 0;
            for (int i = 0; i < chars.length; i++) {
                if (Character.isDigit(chars[i])) {
                    index = i;
                    break;
                }
            }
            productHistoryVO.setDescribe(DescribeType.DescribeType(productHistoryVO.getCode().substring(0, index)));
            productHistoryVO.setDocumentNumber(productHistoryVO.getCode().substring(index));
            productHistoryVO.setCode(productHistoryVO.getCode().substring(0, index));
        }
        return list;
    }
}
